﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace parkingclient
{
    public partial class confirmation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] == null)
            {
                lblWelcome.Text = "[<a href='user_login.aspx'>Login</a>]   [<a href='registration.aspx'>Register</a>]";
            }
            else if (int.Parse(Session["userType"].ToString()) == 3) //for admin, add link to the admin dashboard
            {
                lblWelcome.Text = "Welcome " + Session["user"] + "   [<a href='admin_dashboard.aspx'>Admin Dashboard</a>]    [<a href='user_logout.aspx'>Logout</a>]";
            }
            else
            {
                lblWelcome.Text = "Welcome " + Session["user"] + "   [<a href='user_logout.aspx'>Logout</a>]";
            }

            //check for reservation id in the query argument
            if (Request.QueryString["resid"] == null || Request.QueryString["resid"] == "")
            {
                Label1.Text = "Missing argument. You must be getting to this page by mistake! Click <a href='findres.aspx'>HERE</a> to find your registration";
                Label1.ForeColor = Color.Red;
                return;
            }
            else
            {
                Label1.Text = "Your registration is confirmed!";
            }

            int resid = Int32.Parse(Request.QueryString["resid"]);
    
            //get the reservation details
            ParkingService.WebService1 parking = new ParkingService.WebService1();
            string res = parking.getReservationDetails(resid);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(res);
            XmlNode resNode = xmlDoc.GetElementsByTagName("reservation")[0];

            //populate the fields
            lblResID.Text = resid.ToString();
            lblStartTime.Text = resNode["starttime"].InnerText;
            lblEndTime.Text = resNode["endtime"].InnerText;
            lblSpot.Text = resNode["spotId"].InnerText;

            if(resNode["spotId"].InnerText.StartsWith("1"))
            {
                lblGarage.Text = "South Garage (S. 7th and E. San Salvador)";
                lblMap.Text = "<iframe width='425' height='425' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=san+salvador+and+7th+st,+san+jose,ca&amp;aq=&amp;sll=37.376978,-121.967468&amp;sspn=0.24827,0.528374&amp;ie=UTF8&amp;hq=&amp;hnear=S+7th+St+%26+E+San+Salvador+St,+San+Jose,+Santa+Clara,+California+95112&amp;t=m&amp;ll=37.332426,-121.879406&amp;spn=0.020474,0.025749&amp;z=14&amp;iwloc=A&amp;output=embed'></iframe><br /><small><a href='https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=san+salvador+and+7th+st,+san+jose,ca&amp;aq=&amp;sll=37.376978,-121.967468&amp;sspn=0.24827,0.528374&amp;ie=UTF8&amp;hq=&amp;hnear=S+7th+St+%26+E+San+Salvador+St,+San+Jose,+Santa+Clara,+California+95112&amp;t=m&amp;ll=37.332426,-121.879406&amp;spn=0.020474,0.025749&amp;z=14&amp;iwloc=A' style='color:#0000FF;text-align:left'>View Larger Map</a></small>";
            }
            else if(resNode["spotId"].InnerText.StartsWith("2"))
            {
                lblGarage.Text = "West Garage (S. 4th and E. San Salvador)";
                lblMap.Text = "<iframe width='425' height='425' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=S.+4th+and+E.+San+Salvador+Street,+san+jose,ca&amp;aq=&amp;sll=37.333424,-121.879106&amp;sspn=0.007763,0.016512&amp;ie=UTF8&amp;hq=&amp;hnear=E+San+Salvador+St+%26+S+4th+St,+San+Jose,+Santa+Clara,+California+95112&amp;t=m&amp;ll=37.333382,-121.879578&amp;spn=0.013649,0.025749&amp;z=14&amp;iwloc=A&amp;output=embed'></iframe><br /><small><a href='https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=S.+4th+and+E.+San+Salvador+Street,+san+jose,ca&amp;aq=&amp;sll=37.333424,-121.879106&amp;sspn=0.007763,0.016512&amp;ie=UTF8&amp;hq=&amp;hnear=E+San+Salvador+St+%26+S+4th+St,+San+Jose,+Santa+Clara,+California+95112&amp;t=m&amp;ll=37.333382,-121.879578&amp;spn=0.013649,0.025749&amp;z=14&amp;iwloc=A' style='color:#0000FF;text-align:left'>View Larger Map</a></small>";
            }
            else
            {
                lblGarage.Text = "North Garage (S. 10th and E. San Fernando)";
                lblMap.Text = "<iframe width='425' height='425' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=+S.+10th+and+E.+San+Fernando+Street,+san+jose,ca&amp;aq=&amp;sll=37.333441,-121.881788&amp;sspn=0.007763,0.016512&amp;ie=UTF8&amp;hq=&amp;hnear=S+10th+St+%26+E+San+Fernando+St,+San+Jose,+Santa+Clara,+California+95112&amp;t=m&amp;ll=37.340274,-121.87932&amp;spn=0.013648,0.025663&amp;z=14&amp;iwloc=A&amp;output=embed'></iframe><br /><small><a href='https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=+S.+10th+and+E.+San+Fernando+Street,+san+jose,ca&amp;aq=&amp;sll=37.333441,-121.881788&amp;sspn=0.007763,0.016512&amp;ie=UTF8&amp;hq=&amp;hnear=S+10th+St+%26+E+San+Fernando+St,+San+Jose,+Santa+Clara,+California+95112&amp;t=m&amp;ll=37.340274,-121.87932&amp;spn=0.013648,0.025663&amp;z=14&amp;iwloc=A' style='color:#0000FF;text-align:left'>View Larger Map</a></small>";
            }





        }
    }
}